package com.ucs.ui;

//import java.util.Date;
//import java.util.Timer;
//import java.util.TimerTask;

import com.ucs.util.UCSData;

import android.content.Intent;
import android.os.Bundle;
//import android.util.Log;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends SimpleActivity implements AdapterView.OnItemClickListener, 
	SimpleActivity.ResultCallbackIF{
//    private static final String TAG = "ucs";
    
    private static final int CREATE_ORDER = 0;
    private static final int REVIEW_OPEN_ORDERS = 1;
    private static final int REVIEW_PENDING_ORDERS = 2;

 	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
 		super.onCreate(savedInstanceState);		
		setContentView(R.layout.main);
		
		ArrayAdapter<String> aa = UCSData.getInstance().getMainActionsAdapter(this);
		ListView lv = (ListView)findViewById(R.id.action_listview);
		lv.setAdapter(aa);
		lv.setOnItemClickListener(this);
		
		startService(new Intent(this, SubmitPendingOrderService.class));
//		Timer timer = new Timer(true);
//		timer.schedule(new MyTimerTask(aa), 1000, 1000);
//		timer.
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
		stopService(new Intent(this, SubmitPendingOrderService.class));
	}
	
	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		switch (arg2) {
		case CREATE_ORDER:
			onCreateOrder();
			break;

		case REVIEW_OPEN_ORDERS:
			onReviewOpenOrders();
			break;
		case REVIEW_PENDING_ORDERS:
			onReviewPendingOrders();
			break;
		default:
			break;
		}
	}
	
	private void onCreateOrder(){
		launchSubActivity(NewOrderActivity.class, this, null);
	}
	
	private void onReviewOpenOrders(){
		launchSubActivity(ReviewOpenOrderActivity.class, this, null);
	}
	
	private void onReviewPendingOrders(){
		launchSubActivity(ReviewPendingOrderActivity.class, this, null);
	}
	

	@Override
	public void resultCancel(Intent intent) {
		Log.d("ucs", "+MainActivity:resultCancel");
		Log.d("ucs", "-MainActivity:resultCancel");
		
	}

	@Override
	public void resultOk(Intent intent) {
		Log.d("ucs", "+MainActivity:resultOk");
		Log.d("ucs", "-MainActivity:resultOk");		
	}
}
